import java.util.*;

public class Test12 {
    public static void quickSort(int[] arr,int left,int right){
        if(left>=right){
            return;
        }
        int prior = findPrior(arr,left,right);
        quickSort(arr,left,prior);
        quickSort(arr,prior+1,right);
    }

    public static int findPrior(int[] arr,int left,int right){
        int prior = arr[left];
        while(left<right){
            while(left<right&&arr[right]>=prior){
                right--;
            }
            arr[left] = arr[right];

            while(left<right&&arr[left]<=prior){
                left++;
            }
            arr[right] = arr[left];
        }
        arr[left] = prior;
        return left;
    }
    public static void main(String[] args) {
       int[] arr = new int[]{9,8,7,6,5};
        Random random  =new Random();
        int m = random.nextInt(10);
       quickSort(arr,0,arr.length-1);
       Queue<Integer> queue = new LinkedList<>();
       
        System.out.println(Arrays.toString(arr));
    }
}
